//
//  ObjectDifferenceViewController.m
//  ReviewDemo
//
//  Created by 龙 on 2018/4/27.
//  Copyright © 2018年 long. All rights reserved.
//

#import "ObjectDifferenceViewController.h"
#import "PeopleModel.h"

@interface ObjectDifferenceViewController ()

@end

@implementation ObjectDifferenceViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self judgeArrayIsSame];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 * 使用 isEqual ： 必须实现 isEqual 方法
 */
- (void)judgeArrayIsSame
{
    CarModel *car1 = [[CarModel alloc] init];
    car1.name = @"拖拉机";
    
    CarModel *car2 = [[CarModel alloc] init];
    car2.name = @"拖拉机";
    
    CarModel *car3 = [[CarModel alloc] init];
    car3.name = @"宝马";

    
    DogModel *dog1 = [[DogModel alloc] init];
    dog1.name = @"大狗子";
    
    DogModel *dog2 = [[DogModel alloc] init];
    dog2.name = @"大狗子";

    DogModel *dog3 = [[DogModel alloc] init];
    dog3.name = @"狗腿子";

    
    PeopleModel *people1 = [[PeopleModel alloc] init];
    people1.name = @"张三";
    people1.age = @"20";
    people1.dogsArray = @[dog1,dog3];
    people1.myCar = car1;
    
    PeopleModel *people2 = [[PeopleModel alloc] init];
    people2.name = @"张三";
    people2.age = @"20";
    people2.dogsArray = @[dog2,dog3];
    people2.myCar = car2;

    
    PeopleModel *people3 = [[PeopleModel alloc] init];
    people3.name = @"李四";
    people3.age = @"21";
    people3.dogsArray = @[dog2,dog3];
    people3.myCar = car3;

    NSArray *array1 = @[people1,people3];
    NSArray *array2 = @[people2,people3];
    
    NSLog(@"people1 == people2 ----------- %d",(people1 == people2 ? 1 : 0));
    NSLog(@"[people1 isEqual:people2] ---- %d",[people1 isEqual:people2]);
    NSLog(@"[people1 isEqual:people3] ---- %d",[people1 isEqual:people3]);
    NSLog(@"[array1 isEqual:array2] ------ %d",[array1  isEqual:array2]);

}

@end
